package com.acme.bankapp.domain.bank;

import com.acme.bankapp.domain.bank.exceptions.*;

public class CheckingAccount extends AbstractAccount{
	private double maxOverdraft=0;
	
	/**
	 * Create checking account with 0 overdraft and 0 balance
	 */
	public CheckingAccount() {
		super();
	}

	/**
	 * Create checking account with 0 overdraft
	 * @param balance - initial balance
	 */
	public CheckingAccount(double balance) {
		super(balance);
	}
	
	/**
	 * @param balance - initial balance
	 * @param maxOverdraft - initial overdraft
	 */
	public CheckingAccount(double balance, double maxOverdraft) {
		super(balance);
		this.maxOverdraft = maxOverdraft;
	}

	
	public double getMaxOverdraft() {
		return maxOverdraft;
	}

	public void setMaxOverdraft(double maxOverdraft) {
		this.maxOverdraft = maxOverdraft;
	}

	/**
	 * Withdraw the money from the checking account. If the sum is greater than the balance, overdraft is used
	 * @param sum - amount to withdraw. Should be non-zero
	 */
	@Override
	public void withdraw(double sum) throws NotEnoughFundsException {
		
		if (sum <= 0) {
			throw new IllegalArgumentException("Withdraw amount should be non-zero");
		}
		if (sum > this.maximumAmountToWithdraw()){
			throw new NotEnoughFundsException();
		}
		this.balance -= sum;
		
		assert this.balance >= -this.maxOverdraft;
	}

	/**
	 * Show the maximum amount the client can withdraw. A sum of a balance and an overdraft
	 */
	@Override
	public double maximumAmountToWithdraw() {
		return balance + maxOverdraft;
	}
	

	@Override
	public String toString() {
		return "Checking account";
	}

}
